﻿Public Class frmMessage
#Region "<< -Attributes- >>"
    Public Enum MessageType
        Warning_
        Question_
        Information_
        Error_
    End Enum

    Public Enum MessageButtons
        OkCancel
        Ok
    End Enum

    Public Enum MsgResult
        Ok
        Cancel
    End Enum

    Private _MessageResult As MsgResult = MsgResult.Cancel
#End Region

#Region "<< -Events- >>"
    Public Function ShowMessage(pTitle As String, pMessage As String, pMessageType As MessageType, pButtons As MessageButtons) As MsgResult

        Select Case pMessageType
            Case MessageType.Error_
                imgIcon.Image = My.Resources.Close
                grpCtrol.Text = IIf(String.IsNullOrEmpty(pMessage), "Error", pTitle)
            Case MessageType.Information_
                imgIcon.Image = My.Resources.Info
                grpCtrol.Text = IIf(String.IsNullOrEmpty(pMessage), "Información", pTitle)
            Case MessageType.Question_
                imgIcon.Image = My.Resources.Help
                grpCtrol.Text = IIf(String.IsNullOrEmpty(pMessage), "Interrogación", pTitle)
            Case MessageType.Warning_
                imgIcon.Image = My.Resources.Warning
                grpCtrol.Text = IIf(String.IsNullOrEmpty(pMessage), "Advertencia", pTitle)
            Case Else
                imgIcon.Image = Nothing
                grpCtrol.Text = IIf(String.IsNullOrEmpty(pMessage), "Desconocido", pTitle)
        End Select

        Select Case pButtons
            Case MessageButtons.Ok
                btnButton2.Visible = False
                btnButton1.Text = "Aceptar"
                AddHandler btnButton1.Click, AddressOf btnAccept_Click
            Case MessageButtons.OkCancel
                btnButton1.Visible = True
                btnButton2.Visible = True
                btnButton2.Text = "Aceptar"
                btnButton1.Text = "Cancelar"
                btnButton2.Focus()
                AddHandler btnButton1.Click, AddressOf btnCancel_Click
                AddHandler btnButton2.Click, AddressOf btnAccept_Click
            Case Else
                btnButton1.Visible = False
                btnButton2.Visible = False
        End Select

        txtMessage.Text = pMessage

        Me.ShowDialog()

        Return _MessageResult
    End Function
#End Region

#Region "<< -Private Events- >>"
    Private Sub btnAccept_Click(sender As System.Object, e As System.EventArgs)
        _MessageResult = MsgResult.Ok
        Me.Close()
    End Sub

    Private Sub btnCancel_Click(sender As System.Object, e As System.EventArgs)
        _MessageResult = MsgResult.Cancel
        Me.Close()
    End Sub
#End Region

End Class